<div class="container">
	<div id="loader" class="col-md-offset-1">
	<form class="form-horizontal" role="form" method="post" action="#" id="formuser" onsubmit="return cekDulu(this);">
		<div class="col-md-11">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Request By</b></h4>
				</div>
				<div class="panel-body">
					<div class="col-xs-12 col-sm-6 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Name<span style="color:red;">*</span></label>
							<div class="col-md-7"><input type="text" value="" id="r_name" class="select2 form-control input-sm"></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">ID Number</label>
							<div class="col-md-4">
							<input type="text" value="" id="r_id" class="form-control input-sm" disabled="disabled"/> 
							<!-- Edit by Surya Alam Gultom ~ before id="r_nik" -->
							</div> 
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Manager</label>
							<div class="col-md-7">
							<input type="text" value="" id="r_mgr" class="form-control input-sm" disabled="disabled"/>
							<!-- Edit by Surya Alam Gultom ~ before id="r_manager" -->
							</div>
						</div>
					</div>
					<div class="col-xs-6 col-sm-6 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Departement</label>
							<div class="col-md-7">
							<input type="text" value="" id="r_dept" class="form-control input-sm" disabled="disabled"/>
							<!-- Edit by Surya Alam Gultom ~ before id="r_department" -->
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Job Position</label>
							<div class="col-md-8">
							<input type="text" value="" id="r_job" class="form-control input-sm" disabled="disabled"/>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="panel panel-default">
				<div class="panel-heading"><h4 class="panel-title"><b class="caret"></b><b> Form</b></h4></div>
				<div class="panel-body">
					<div class="col-sm-6 col-md-6">
						<div class="form-group">
							<label class="col-md-5">Courier<span style="color:red;">*</span></label>
							<div class="col-md-5">
								<select id="courier" class="form-control input-sm" onchange="javascript:getArea()">
									<option value="">Select Courier</option>
									<option value="DOM">Domestic</option>
									<option value="INT">International</option>
									<option value="MES">Messenger</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-5">Category</label>
							<div class="col-md-4">
								<select class="form-control input-sm" id="category">
									<option value="Reguler">Reguler</option>
									<option value="Insidential">Insidential</option>
								</select>
							</div>
						</div>					
						<div class="form-group">
							<label class="col-md-5">Cargo Type</label>
							<div class="col-md-5">
								<select class="form-control input-sm" id="cargo_type">
									<option value="Dokumen">Document</option>
									<option value="Non Dokumen">Non Document</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-5">Location Pickup</label>
							<div class="col-md-4">
								<select class="form-control input-sm" id="lokasi_jemput">
									<option value="User">User</option>
									<option value="Dmr">Mailing Room</option>
								</select>
							</div>		
						</div>
						<div class="form-group">
							<label class="col-md-5">Time to Pickup</label>
							<div class="col-md-4">
								<select id="waktu_jemput" class="form-control input-sm">
									<?php if ($P_Time == 1) {echo "<option value='10' selected>10:00</option>";} 
										else {echo "<option value='15' selected>15:00</option>";} ?>
								</select>
							</div>
						</div>
					</div>
					<div class="col-sm-6 col-md-6">
						<div class="form-group" id="Area">
							<label class="col-md-5">Destination Area<span style="color:red;">*</span></label>
							<div class="col-md-6">
								<select id="D_Area" class="form-control input-sm" onchange="javascript:getReg(this)">
									<option value="">Select Courier First</option>
								</select>
							</div>
						</div>
						<div class="form-group" id="Regional">
							<label class="col-md-4">Regional<span style="color:red;">*</span></label>
							<div class="col-md-7">
								<input type="text" value="" id="D_Regional" class="select2 form-control input-sm">
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-4">Floor<span style="color:red;">*</span></label>
							<div class="col-md-2">
								<input type="text" value="" id="lantai" class="form-control input-sm" />
							</div>
							
							<label class="col-md-2">Weight<span style="color:red;">*</span></label>
							<div class="col-md-2">
								<input type="text" value="" id="weight" class="form-control input-sm" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-4">Description<span style="color:red;">*</span></label>
							<div class="col-md-8">
								<textarea id="deskripsi" class="form-control input-sm" style="min-width:190px;max-width:200px;min-height:100px;max-height:200px;"></textarea>
							</div>
						</div>
					</div>
					<div class="col-md-11">
						<div class="form-group" style="text-align:center">
							<input type="submit" value="Save This Form" name="submit" class="btn btn-success btn-md"/> <!-- onclick="return ConfirmFormDmrAdd();" -->
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>

<script type="text/javascript">
    $.validator.setDefaults({
        submitHandler: function() {
            $.post("<?= site_url() ?>public_room/insert_dmr", {
                r_id: $('#r_id').val(), 
                r_mgr: $('#r_mgr').val(), 
                courier: $('#courier').val(), 
				category: $('#category').val(), 
				cargo_type: $('#cargo_type').val(), 
				location: $('#lokasi_jemput').val(), 
				timed: $('waktu_jemput').val(), 
				D_Area: $('D_Area').val(), 
				D_Regional: $('D_Regional').val(), 
				lantai: $('#lantai').val(), 
				weight: $('#weight').val(), 
				deskripsi: $('#deskripsi').val() 
            },
            function(data) {
                $('#loader').html(data);
            });
        }
    });

    $(document).ready(function() {
        $("#formuser").keypress(function(e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                $.validator.setDefaults({
                    submitHandler: function() {
                        $.post("<?= site_url() ?>public_room/insert_dmr", {
                            r_id: $('#r_id').val(), 
							r_mgr: $('#r_mgr').val(), 
                			courier: $('#courier').val(), 
							category: $('#category').val(), 
							cargo_type: $('#cargo_type').val(), 
							location: $('#lokasi_jemput').val(), 
							timed: $('waktu_jemput').val(), 
							D_Area: $('D_Area').val(), 
							D_Regional: $('D_Regional').val(), 
							lantai: $('#lantai').val(), 
							weight: $('#weight').val(), 
							deskripsi: $('#deskripsi').val() 
                        },
                        function(data) {
                            $('#loader').html(data);
                        });
                    }
                });
            }
        });

        $("#formuser").validate();
    });

	function getArea()
	{
		var courier_id = {courier_id:$("#courier").val()};
		$.ajax({
				type: "POST",
				url : "<?php echo site_url('public_room/ShowArea');?>",
				data: courier_id,
				success: function(msg){$('#Area').html(msg);}
			});
	};
	
	function getReg(area_name)
	{
			var getarea = {area_name:area_name.value};
			$.ajax({
				type: "POST",
				url : "<?php echo site_url('public_room/ShowRegional');?>",
				data: getarea,
				dataType:'json',
				success: function(data)
				{
					$('#D_Regional').select2({
						id: function(bond){ return bond.AREA_ID;},
					ajax:({	
						type:"POST",
						dataType:'json',
						url: "<?php echo site_url('public_room/getRegional')?>",
						data: function(term)
						{
							return {
										SearchReg:data,
										term:term
							};
						},
						results: function(bond, page) {return {results: bond.Show_Region, more: (bond.Show_Region && bond.Show_Region.length == 10 ? true: false)}}
						}),
						formatResult: function(bond) {return '<div class="select2-user-result">' + bond.REGIONAL_NAME + '</div>'},
						formatSelection: function(bond){return bond.REGIONAL_NAME},
						initSelection: function(elem, cb){return elem}
					});
				}
			});
	};

	function cekDulu(frm) {
		/*
		if (frm.elements['r_name'].value.length==0) {
			alert('Pilih Requestor nya');
			return false;
		}
		if (frm.elements['courier'].value.length==0) {			
			alert('Pilih Jasa Kurir nya');
			frm.elements['courier'].focus();
			return false;
		}
		if (frm.elements['D_Area'].value=='0') {			
			alert('Pilih Area Tujuan nya');
			frm.elements['D_Area'].focus();
			return false;
		}
		if (frm.elements['D_Regional'].value.length==0) {			
			alert('Pilih Regional nya');
			return false;
		}
		if (frm.elements['lantai'].value.length==0) {			
			alert('Pilih Lantai nya');
			frm.elements['lantai'].focus();
			return false;
		}
		if (frm.elements['weight'].value.length==0) {			
			alert('Pilih Berat nya');
			frm.elements['weight'].focus();
			return false;
		}
		if (frm.elements['deskripsi'].value.length==0) {
			frm.elements['deskripsi'].focus();
			//document.getElementById('deskripsi').focus();
			alert('Isi Deskripsi nya');
			return false;
		}
		*/
	}
	
</script>